package com.bjsxt.ploymophism;

class TestPolym {
    public static void main(String[] args) {

        Dog d = new Dog();
        animalCry(d);
        Cat c = new Cat();
        animalCry(c);
        Animal a1 = new Cat();
        animalCry(a1);
        //
        Animal a =new Dog();
//      a.seeDoor();
        Dog d2 = (Dog) a;
        d2.seeDoor();
        Cat c3 = (Cat) a;  //java.lang.ClassCastException
        c3.catchMouse();

        if(a instanceof Dog){
            Dog d3=(Dog) a;
            d3.seeDoor();
        }
    }

    static void animalCry(Animal a) {
        a.shout();
    }
}
